#ifndef __SERIAL_PORT_H__
#define __SERIAL_PORT_H__

#ifdef __cplusplus
 extern "C" {
#endif

#include <stdint.h>
#include <termios.h>
#include <pthread.h>

#ifndef SERIAL_ASYNC_RECV_BUFF_SIZE
#define SERIAL_ASYNC_RECV_BUFF_SIZE				1024
#endif
#define INSTANCE_SERIAL_T(instance)		\
struct serial_t instance={ \
	.tty=NULL, \
	.baudrate = 9600, \
	.fd = -1, \
	.async_recv_callback = NULL, \
	.tid = 0, \
} \

struct serial_t{
	char *tty;
	int baudrate;
	int fd;
	void (*async_recv_callback)(struct serial_t *,void *,uint32_t);			//异步接收的回调函数
	struct termios termios;
	pthread_t tid;															//异步接收进程的进程号
};

extern int serial_device_init(struct serial_t *dev,char *tty,uint32_t baudrate,void (*async_callback)(struct serial_t *,void *,uint32_t));
extern int serial_device_deinit(struct serial_t *dev);
extern int write_serial(struct serial_t *dev,unsigned char * data, int data_len);
extern int sync_read_serial(struct serial_t *dev,void *data, int data_len,uint32_t time);


#ifdef __cplusplus
}
#endif
#endif /* __SERIAL_PORT_H__ */

